﻿using System.Linq;
using Abp.Authorization;
using Abp.Localization;
using LeadThing.AbpZeroTemplate.Authorization;



namespace LeadThing.AbpZeroTemplate.SpecialPersons.Authorization
{
    /// <summary>
    /// 权限配置都在这里。
    /// 给权限默认设置服务
    /// See <see cref="SpecialPersonAppPermissions"/> for all permission names.
    /// </summary>
    public class SpecialPersonAppAuthorizationProvider : AuthorizationProvider
    {
        public override void SetPermissions(IPermissionDefinitionContext context)
        {
            //在这里配置了SpecialPerson 的权限。

            var pages = context.GetPermissionOrNull(AppPermissions.Pages) ?? context.CreatePermission(AppPermissions.Pages, L("Pages"));

            var entityNameModel = pages.Children.FirstOrDefault(p => p.Name == AppPermissions.Pages_GridManage)
              ?? pages.CreateChildPermission(AppPermissions.Pages_GridManage, L("Pages_GridManage"));





            var specialPerson = entityNameModel.CreateChildPermission(SpecialPersonAppPermissions.SpecialPerson, L("SpecialPerson"));
            specialPerson.CreateChildPermission(SpecialPersonAppPermissions.SpecialPerson_CreateSpecialPerson, L("CreateSpecialPerson"));
            specialPerson.CreateChildPermission(SpecialPersonAppPermissions.SpecialPerson_EditSpecialPerson, L("EditSpecialPerson"));
            specialPerson.CreateChildPermission(SpecialPersonAppPermissions.SpecialPerson_DeleteSpecialPerson, L("DeleteSpecialPerson"));

        }

        private static ILocalizableString L(string name)
        {
            return new LocalizableString(name, AbpZeroTemplateConsts.LocalizationSourceName);
        }
    }

}